package com.gree.changying.activity.mainactivity.framgent.homefrm;


import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.gree.changying.R;
import com.gree.changying.activity.base.BasePageFragment;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.adapter.GdhlAdapter;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.adapter.ViewPagerAdapter;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.bean.Gdhl;
import com.gree.changying.view.AutoViewPager;
import com.gree.changying.widget.tablayout.jtablayout.tab.Tab;
import com.gree.changying.widget.tablayout.widget.JTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ZuQiuFenxiFrm extends BasePageFragment {
    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        init();
        initHaoliao();
        inithaoliao1();
    }


    @Bind(R.id.haoliaoTab)
    JTabLayout haoliaoTab;
    @Bind(R.id.haoliaoPager)
    AutoViewPager haoliaoPager;
    ViewPagerAdapter haoliaoAdapter;
    private void initHaoliao(){
        haoliaoAdapter = new ViewPagerAdapter();
        haoliaoPager.setAdapter(haoliaoAdapter);
        haoliaoPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                haoliaoTab.selectTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        haoliaoTab.addOnTabSelectedListener(new JTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(@NonNull Tab var1) {
                haoliaoPager.setCurrentItem(var1.getPosition());
            }

            @Override
            public void onTabUnselected(@NonNull Tab var1) {

            }

            @Override
            public void onTabReselected(@NonNull Tab var1) {

            }
        });
        initHaoliaoData();
    }
    private String[] haoliao = {"好料推介","百家贴士","足球前瞻","赛事动态","盘口分析"};
    private Object[][] haoliaoList = {
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"}
    };
    private List<Gdhl> getHaoliao(){
        List<Gdhl> rmsses = new ArrayList<>();
        for(Object[] o:haoliaoList){
            Gdhl rmss = new Gdhl();
            rmss.setTitle((String)o[0]);
            rmss.setDate((String)o[1]);
            rmsses.add(rmss);
        }
        return rmsses;
    }
    private void initHaoliaoData(){
        List<View> views = new ArrayList<>();
        for(String s:haoliao){
            Tab tab = haoliaoTab.newTab().setTitle(s);
            tab.setTitleColor(getResources().getColor(R.color.tabHaoliao)
                    ,getResources().getColor(R.color.tabHaoliaoP));
            haoliaoTab.addTab(tab);
            View tView =  LayoutInflater.from(mContext).inflate(R.layout.pager_recycleview, null);
            RecyclerView rv = tView.findViewById(R.id.rv);
            rv.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            rv.setHasFixedSize(true);
            GdhlAdapter gdhlAdapter = new GdhlAdapter(R.layout.item_tuijian_gdhl,getHaoliao());
            gdhlAdapter.setHasStableIds(true);
            rv.setAdapter(gdhlAdapter);
            views.add(tView);
        }
        haoliaoAdapter.update(views);
        haoliaoPager.setCurrentItem(0);
    }

    @Bind(R.id.haoliao1Tab)
    JTabLayout haoliao1Tab;
    @Bind(R.id.haoliao1Pager)
    AutoViewPager haoliao1Pager;
    ViewPagerAdapter haoliao1Adapter;
    private void inithaoliao1(){
        haoliao1Adapter = new ViewPagerAdapter();
        haoliao1Pager.setAdapter(haoliao1Adapter);
        haoliao1Pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                haoliao1Tab.selectTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        haoliao1Tab.addOnTabSelectedListener(new JTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(@NonNull Tab var1) {
                haoliao1Pager.setCurrentItem(var1.getPosition());
            }

            @Override
            public void onTabUnselected(@NonNull Tab var1) {

            }

            @Override
            public void onTabReselected(@NonNull Tab var1) {

            }
        });
        inithaoliao1Data();
    }
    private String[] haoliao1 = {"前线爆料","赔率知识","实力数据","看盘技巧","欧亚攻略"};
    private Object[][] haoliao1List = {
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"},
            {"会告诉对方不干涉对方的的公司的","02-20 18:30"}
    };
    private List<Gdhl> gethaoliao1(){
        List<Gdhl> rmsses = new ArrayList<>();
        for(Object[] o:haoliao1List){
            Gdhl rmss = new Gdhl();
            rmss.setTitle((String)o[0]);
            rmss.setDate((String)o[1]);
            rmsses.add(rmss);
        }
        return rmsses;
    }
    private void inithaoliao1Data(){
        List<View> views = new ArrayList<>();
        for(String s:haoliao1){
            Tab tab = haoliao1Tab.newTab().setTitle(s);
            tab.setTitleColor(getResources().getColor(R.color.tabHaoliao)
                    ,getResources().getColor(R.color.tabHaoliaoP));
            haoliao1Tab.addTab(tab);
            View tView =  LayoutInflater.from(mContext).inflate(R.layout.pager_recycleview, null);
            RecyclerView rv = tView.findViewById(R.id.rv);
            rv.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            rv.setHasFixedSize(true);
            GdhlAdapter gdhlAdapter = new GdhlAdapter(R.layout.item_tuijian_gdhl,gethaoliao1());
            gdhlAdapter.setHasStableIds(true);
            rv.setAdapter(gdhlAdapter);
            views.add(tView);
        }
        haoliao1Adapter.update(views);
        haoliao1Pager.setCurrentItem(0);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.frm_zuqiubifen;
    }

    private void init(){

    }
}
